import { EnumBetResult, EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RoundInfo, ExcutePlan, RecmInfo } from "../ExecutePlan";
import { ExcutePlanWithSubPlan } from "../ExcutePlanWithSubPlan";
import { FixedValueStrategy } from "../recmStrategy/FixedStrategy";
import { PlanAMoneyStrategy, PlanBMoneyStrategy } from "../moneyStrategy/WisdomMoneyStrategyV35Group";
import { FollowStrategy } from "../recmStrategy/FollowStrategy";
import { BossRabbitMoneyStrategy } from "../moneyStrategy/BossRabitMoneyStrategy";
import { ArrayIndexStrategy } from "../recmStrategy/ArrayStrategy";

export class WisdomePlan3_6 extends ExcutePlanWithSubPlan {
    planA: ExcutePlan = (new ExcutePlan());
    planB: ExcutePlan = (new ExcutePlan());
    planC: ExcutePlan = (new ExcutePlan());
    planD: ExcutePlan = (new ExcutePlan());
    planE: ExcutePlan = (new ExcutePlan());
    planF: ExcutePlan = (new ExcutePlan());
    planG: ExcutePlan = (new ExcutePlan());
    constructor() {
        super();
        let multiple = this.planA.multiple;
        this.planA = new ExcutePlan();
        this.planA.planName = 'A计划';
        this.planA.multiple = multiple;
        this.planA.recmStrategy = [
            new FixedValueStrategy({ reverse: false, result: EnumBjlResult.Z })
        ];
        this.planA.moneyStrategy = [new PlanAMoneyStrategy("A计划", {
            baseMoney: 10,
            stopLFailCount: 3,
            failStepCount: 1,
            winStepCount: -1,
            stepMoney: 10
        })];
        this.planA.toResult(new RoundInfo());

        this.planB = new ExcutePlan();
        this.planB.planName = 'B计划';
        this.planB.multiple = multiple;
        this.planB.recmStrategy = [
            new FixedValueStrategy({ reverse: false, result: EnumBjlResult.Z })
        ];
        this.planB.moneyStrategy = [
            new PlanBMoneyStrategy("B计划", {
                baseMoney: 10,
                stopLFailCount: 3,
                failStepCount: -2,
                winStepCount: 1,
                stepMoney: 10,
            }, this.planA)
        ];
        this.planB.toResult(new RoundInfo());

        multiple = this.planC.multiple;
        this.planC = new ExcutePlan();
        this.planC.planName = 'C计划';
        this.planC.multiple = multiple;
        this.planC.recmStrategy = [
            new FixedValueStrategy({ reverse: false, result: EnumBjlResult.X })
        ];
        this.planC.moneyStrategy = [
            new PlanAMoneyStrategy("C计划", {
                baseMoney: 10,
                stopLFailCount: 3,
                failStepCount: 1,
                winStepCount: -1,
                stepMoney: 10
            })
        ];
        this.planC.toResult(new RoundInfo());

        multiple = this.planD.multiple;
        this.planD = new ExcutePlan();
        this.planD.planName = 'D计划';
        this.planD.multiple = multiple;
        this.planD.recmStrategy = [
            new FixedValueStrategy({ reverse: false, result: EnumBjlResult.X })
        ];
        this.planD.moneyStrategy = [
            new PlanBMoneyStrategy("D计划", {
                baseMoney: 10,
                stopLFailCount: 3,
                failStepCount: -2,
                winStepCount: 1,
                stepMoney: 10,
            }, this.planC)
        ];
        this.planD.toResult(new RoundInfo());

        multiple = this.planE.multiple;
        this.planE = new ExcutePlan();
        this.planE.planName = "E计划";
        this.planE.multiple = multiple;
        this.planE.recmStrategy = [
            //new FixedValueStrategy({ reverse: false, result: EnumBjlResult.Z })
            new FollowStrategy({
                followCount: 2,
                reverse: false
            })
        ];
        this.planE.moneyStrategy = [new BossRabbitMoneyStrategy("方案一", {
            baseMoney: 10,
            winStep: 1,
            failStep: 0,
            prevMoney: 0,
            currentMoney: 10,
            prevPrevMoney: 0,
            maxMoney: 9999999999,
            changeMoney: 999999999
        })];
        [this.planE.recmInfo.recmV, this.planE.recmInfo.recmMoney] = this.planE.toMoney(new RoundInfo(), this.planE.recmInfo, this.planE.userRecmInfo, this.planE.baseMoney);

        multiple = this.planF.multiple;
        this.planF = new ExcutePlan();
        this.planF.planName = "F计划";
        this.planF.multiple = multiple;
        this.planF.running = false;
        this.planF.recmStrategy = [
            new ArrayIndexStrategy({
                betArray: [EnumBjlResult.X, EnumBjlResult.X, EnumBjlResult.X, EnumBjlResult.Z],
                reset: -1
            })
        ];
        this.planF.moneyStrategy = [new BossRabbitMoneyStrategy("方案一", {
            baseMoney: 10,
            winStep: 1,
            failStep: 0,
            prevMoney: 0,
            currentMoney: 10,
            prevPrevMoney: 0,
            maxMoney: 9999999999,
            changeMoney: 999999999
        })];

        multiple = this.planG.multiple;
        this.planG = new ExcutePlan();
        this.planG.planName = "G计划";
        this.planG.running = false;
        this.planG.multiple = multiple;
        this.planG.recmStrategy = [
            new ArrayIndexStrategy({
                betArray: [EnumBjlResult.Z, EnumBjlResult.Z, EnumBjlResult.Z, EnumBjlResult.X],
                reset: -1
            })
        ];
        this.planG.moneyStrategy = [new BossRabbitMoneyStrategy("方案一", {
            baseMoney: 10,
            winStep: 1,
            failStep: 0,
            prevMoney: 0,
            currentMoney: 10,
            prevPrevMoney: 0,
            maxMoney: 9999999999,
            changeMoney: 999999999
        })];
        this.subPlan = [
            this.planA,
            this.planB,
            this.planC,
            this.planD,
            this.planE,
            this.planF,
            this.planG
        ];
    }

    /**
     * 计算本地投注方向
     * @param roundInfo 信息
     */
    toMoney(roundInfo: RoundInfo, recmInfo: RecmInfo, userRecm: RecmInfo, baseMoney: number): [EnumBjlResult, number] {
        let money = 0;
        let recmV = EnumBjlResult.U;
        let recmMoney = 0;
        let result = roundInfo.currentResult;
        this.subPlan.forEach((pl, idx) => {
            let plRoundInfo = Object.assign({}, roundInfo);
            if (pl.recmInfo.recmV != EnumBjlResult.U) {
                plRoundInfo.recmResult = result == pl.recmInfo.recmV ? EnumBetResult.Success : EnumBetResult.Fail;
            }
            else {
                plRoundInfo.recmResult = EnumBetResult.NotBet;
            }

            if (idx == 5) {
                if (this.subPlan[0].recmInfo.summaryInfo.winCount >= this.subPlan[0].recmInfo.summaryInfo.failCount && pl.running) {
                    pl.running = false;
                }
                else if (!pl.running && result == EnumBjlResult.Z && this.subPlan[0].recmInfo.summaryInfo.winCount < this.subPlan[0].recmInfo.summaryInfo.failCount) {
                    pl.resetPlan();
                }
            }


            if (idx == 6) {
                if (this.subPlan[2].recmInfo.summaryInfo.winCount >= this.subPlan[2].recmInfo.summaryInfo.failCount && pl.running) {
                    pl.running = false;
                } else if (!pl.running && result == EnumBjlResult.X && this.subPlan[2].recmInfo.summaryInfo.winCount < this.subPlan[2].recmInfo.summaryInfo.failCount) {
                    pl.resetPlan();
                }
            }


            if (pl.running) {

                let plUserRecmV = pl.toResult(plRoundInfo);
                plRoundInfo.userRecm = plUserRecmV;
                pl.userRecmInfo.recmV = plUserRecmV;
                let [planARecmV, planARecmMoney] = pl.toMoney(plRoundInfo, pl.recmInfo, pl.userRecmInfo, pl.baseMoney);
                pl.recmInfo.recmV = planARecmV;
                pl.recmInfo.recmMoney = planARecmMoney;
            }
            else {
                pl.recmInfo.recmV = EnumBjlResult.U;
                pl.recmInfo.recmMoney = 0;
            }


            if (pl.recmInfo.recmV == EnumBjlResult.Z) {
                money += (pl.recmInfo.recmMoney * pl.multiple);
            }
            else if (pl.recmInfo.recmV == EnumBjlResult.X) {
                money -= (pl.recmInfo.recmMoney * pl.multiple);
            }
        });
        if (money > 0) {
            recmV = EnumBjlResult.Z;
            recmMoney = Math.abs(money);
        }
        else if (money < 0) {
            recmV = EnumBjlResult.X;
            recmMoney = Math.abs(money);
        }
        else {
            recmV = EnumBjlResult.U;
            recmMoney = 0;
        }
        return [recmV, recmMoney];
    }
}